/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package titanisu.basicMathModule1.identityAssociativeRules7;

import com.sun.script.javascript.RhinoScriptEngine;
import java.util.ArrayList;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.ScriptException;

/**
 *
 * @author Balaji
 */
public class QuestionGeneratorAddSub {

    ArrayList quest = new ArrayList();

    private void setQ(ArrayList arlst) {
        this.quest = arlst;
    }

    public ArrayList getQuest() {
        return quest;
    }

    public void setQuest(ArrayList quest) {
        this.quest = quest;
    }

    /*
     * Generates a single question in below format is forms and array with question and nominator and denominator
     * The final the arraylist is put in variable quest and this methog returns a string putting forward only question
     * quest.get(0) question string
     * quest.get(1) answer nominator
     * quest.get(0) answer denominator
     * 
     * @param: void
     * @returns : String having question
     */
    public String getQuestions() {
        int variables[] = new int[5];
        String[] question = new String[10];

        int a = (new Random()).nextInt(1000);
        int b = (new Random()).nextInt(1000);
        int c = (new Random()).nextInt(1000);


        System.out.println("before negating the values intQ = " + intQ);
        if (intQ) {
            if (Math.random() > .5) {
                a *= -1;
            }

            if (Math.random() > .5) {
                b *= -1;
            }

            if (Math.random() > .5) {
                c *= -1;
            }
        }


        /*
         * commutatuve rule
         */

        int qType = (new Random()).nextInt(14);
        switch (qType) {
            case 0:
                String temp = "Is " + a + "+" + b + "=" + b + "+" + a + "?\nAnswer true or false.";
                quest.add(0, temp);
                quest.add(1, "true");
                break;
            case 1:
                String temp1 = "Is " + a + "+" + b + "+" + c + "=" + c + "+" + b + "+" + a + "?\nAnswer true or false.";
                quest.add(0, temp1);
                quest.add(1, "true");
                break;
            case 2:
                String temp2 = "Is " + a + "*" + b + "=" + b + "*" + a + "?\nAnswer true or false.";
                quest.add(0, temp2);
                quest.add(1, "true");

                break;
            case 3:
                String temp3 = "Is " + c + "(" + a + "+" + b + ") = (" + c + "*" + b + "+" + c + "*" + a + ") ?\nAnswer true or false.";
                quest.add(0, temp3);
                quest.add(1, "true");

                break;
            case 4:
                String temp4 = "Is " + a + "+" + b + "=" + b + "+" + a + "?\nIf Yes, what is this rule called?";
                quest.add(0, temp4);
                quest.add(1, "Commutative");

                break;
            case 5:
                String temp5 = "Is " + c + "(" + a + "+" + b + ") = (" + c + "*" + b + "+" + c + "*" + a + ") ?\nIf Yes, what is this rule called?";
                quest.add(0, temp5);
                quest.add(1, "Distributive");

                break;
            case 6:
                ;
                quest.add(0, "Is " + a + "+" + b + "=" + b + "-" + a + "?\nAnswer true or false.");
                quest.add(1, "false");
                break;
            case 7:
                quest.add(0, "Is " + a + "-" + b + "=" + b + "-" + a + "?\nAnswer true or false.");
                quest.add(1, "false");
                break;
            case 8:
                ;
                quest.add(0, "Is " + a + "/" + b + "=" + b + "/" + a + "?\nAnswer true or false.");
                quest.add(1, "false");
                break;
            case 9:
                quest.add(0, "Is " + a + "+" + c + "=" + b + "+" + a + "?\nAnswer true or false.");
                quest.add(1, "false");
                break;
            case 10:
                quest.add(0, "Is " + c + "(" + a + "+" + b + ") = (" + b + "*" + c + "+" + c + "*" + a + ") ?" + "?\nAnswer true or false.");
                quest.add(1, "true");
                break;
            case 11:
                quest.add(0, "Is " + c + "(" + a + "+" + b + ") = (" + b + "*" + c + "+" + a + "*" + c + ") ?" + "?\nAnswer true or false.");
                quest.add(1, "true");
                break;
            case 12:
                quest.add(0, "Is " + c + "(" + a + "+" + b + ") = (" + b + "*" + c + "*" + a + "*" + c + ") ?" + "?\nAnswer true or false.");
                quest.add(1, "false");
                break;
            case 13:
                quest.add(0, "Is " + c + "(" + a + "+" + (new Random().nextInt(1000)) + ") = (" + b + "*" + c + "+" + a + "*" + c + ") ?" + "?\nAnswer true or false.");
                quest.add(1, "false");
                break;
            default:
                throw new AssertionError();
        }
        setQ(quest);
        //        System.out.println(" quest set in questionGenerator is " + quest);



        System.out.println(" the quest is " + quest);
        return (String) quest.get(0);
    }

    /**
     * Gives the answers
     *
     * @return
     */
    public String getAnswer() {
        String answer = "";
        String den = (String) quest.get(1);
        return answer;
    }
    boolean intQ = false;

    void setIntegers(boolean b) {
        intQ = b;
    }
}
